using System.Text;
using BuildingBlocks.Infrastructure.Email;
using Identity.Application.Contracts.Services;
using Identity.Infrastructure.EventHandlers;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace Identity.Infrastructure.Services;

public class EmailService : IEmailService
{
    private readonly IEmailSender _emailSender;
    private readonly IUserService _userIdentityService;
    private readonly IConfiguration _configuration;
    private readonly ILogger<UserRegisteredEventHandler> _logger;
    public EmailService(
            IEmailSender emailSender,
            IUserService userIdentityService,
            IConfiguration configuration,
            ILogger<UserRegisteredEventHandler> logger)
    {
        _emailSender = emailSender;
        _userIdentityService = userIdentityService;
        _configuration = configuration;
        _logger = logger;
    }

    public async Task<string> ConvertBase64UrlEncodeAsync(string token)
    {
        return  WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(token));
    }

    public async Task SendEmailAsync(string email, string title, string context)
    {
        await _emailSender.SendEmailAsync(email, title, context);
    }

    
}